﻿using SurfaceAd.Assistant;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/**
 * 创建时间：2014/9/19 10:41:04
 * 作者：yong.blackcore
 * Email：itblackhole@outlook.com
 * QQ：50404503
 */
namespace SurfaceAd.Common
{
    public sealed class LogHelper
    {
        private enum LogLocation
        {
            CONSOLE,
            FILE
        }

        private static LogHelper.LogLocation logLocation = LogHelper.LogLocation.CONSOLE;
        private static string INFO_TAG = "INFO";
        private static string ERROR_TAG = "ERROR";


        public static void LogInfo(string msg)
        {
            LogInfo(msg, null, null);
        }

        public static void LogInfo(string msg, Type type)
        {
            LogInfo(msg, type, null);
        }

        public static void LogInfo(string msg, Type type, string methodName)
        {

            LogHelper.LogMessage(string.Format("{0}:{1}.{2}#{3}#{4}=>\t{5}", new object[]
				{
                    DateTime.Now.ToString(Constants.DATETIME_FORMAT),
                    type == null?string.Empty:type.Name,
                    methodName,
					Constants.AdSDKVersion,
					LogHelper.INFO_TAG,
					msg
				}));

        }


        /// <summary>
        /// 输出错误日志
        /// </summary>
        /// <param name="msg"></param>
        public static void LogError(string msg)
        {
            LogError(msg, null, null);
        }

        /// <summary>
        /// 输出错误日志
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="type"></param>
        public static void LogError(string msg, Type type)
        {
            LogError(msg, type, null);
        }

        /// <summary>
        /// 输出错误日志
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="type">this.GetType()|typeof(classname)</param>
        /// <param name="method">MethodBase.GetCurrentMethod()</param>
        public static void LogError(string msg, Type type, string methodName)
        {
            LogHelper.LogMessage(string.Format("{0}:{1}.{2}#{3}#{4}=>\t{5}", new object[]
				{
                    DateTime.Now.ToString(Constants.DATETIME_FORMAT),
                    type == null?string.Empty:type.Name,
                     methodName,			
					Constants.AdSDKVersion,
					LogHelper.ERROR_TAG,
					msg
				}));
        }

        public static void LogMessage(string msg)
        {
            if (LogHelper.logLocation == LogHelper.LogLocation.CONSOLE)
            {
#if DEBUG
                Debug.WriteLine(msg);
#endif
            }
        }
    }
}
